import { BasicColumn, FormSchema } from '@/components/Table';
import { uploadStatic } from '@/api/static/static';
import { h } from 'vue';
import { Image } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    title: '模板ID',
    dataIndex: 'id',
    width: 80,
  },
  {
    title: '模板名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '简介',
    dataIndex: 'desc',
    width: 200,
  },
  {
    title: '预览图',
    dataIndex: 'cover',
    width: 120,
    customRender: ({ record }) => {
      return h(Image, {
        src: record.cover,
        height: 40,
        style: { objectFit: 'cover' },
      });
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      return record.status === 10 ? '启用' : '禁用';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updated_at',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '模板名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '模板名称',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'desc',
    label: '简介',
    component: 'InputTextArea',
    colProps: { span: 24 },
  },
  {
    field: 'cover',
    label: '预览图',
    component: 'Upload',
    colProps: { span: 24 },
    componentProps: {
      api: uploadStatic,
      maxSize: 2,
      maxNumber: 1,
      accept: ['image/*'],
      multiple: false,
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 10,
    required: true,
    colProps: { span: 24 },
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
  },
];
